/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import {Form, Input, Radio, Select, Switch, DatePicker } from 'antd';
import {connect} from 'dva';
import moment from 'moment'
const FormItem = Form.Item;
const { TextArea } = Input;
const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 6},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               名称
            </span>
            )}
          >
            {getFieldDecorator('name', {
              initialValue: this.props.editRecord ? this.props.editRecord.name : '',
              rules: [{ required: true, message: '请输入名称' }],
            })(
              <Input />
            )}
          </FormItem>
          {
            !this.props.editRecord&&
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               IMEI
            </span>
              )}
            >
              {getFieldDecorator('imei', {
                initialValue: this.props.editRecord ? this.props.editRecord.imei : '',
                rules: [{ required: true, message: '请输入imei' }],
              })(
                <Input />
              )}
            </FormItem>
          }
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               IMSI
            </span>
            )}
          >
            {getFieldDecorator('imsi', {
              initialValue: this.props.editRecord ? this.props.editRecord.imsi : '',
              rules: [{ required: true, message: '请输入IMSI' }],
            })(
              <Input />
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               订阅设备资源
            </span>
            )}
          >
            {getFieldDecorator('is_observe', {
              initialValue: this.props.editRecord ? this.props.editRecord.is_observe.toString() : '',
              rules: [{ required: true, message: '请选择' }],
            })(
              <Select >
                { [{key:'-1',value:'关闭'},{key:'1',value:'开启'}].map(item => <Option key={item.key} value={item.key}>{item.value}</Option>) }
              </Select>
            )}
          </FormItem>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               Auth Code
            </span>
            )}
          >
            {getFieldDecorator('auth_code', {
              initialValue: this.props.editRecord ? this.props.editRecord.auth_code : '',
            })(
              <Input />
            )}
          </FormItem>
          {
            !this.props.editRecord&&
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               PSK
            </span>
              )}
            >
              {getFieldDecorator('psk', {
                initialValue: this.props.editRecord ? this.props.editRecord.psk : '',
              })(
                <Input />
              )}
            </FormItem>
          }
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
               描述
            </span>
            )}
          >
            {getFieldDecorator('description', {
              initialValue: this.props.editRecord ? this.props.editRecord.description : '',
            })(
              <Input />
            )}
          </FormItem>
        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


